Prints formatted data to a string while limiting the maximum number of characters to produce.
#include <stdio.h> int snprintf(char *buffer, size_t size, const char *format[, argument]...); int snprintf_s(char *buffer, rsize_t size, const char *format[, argument]...);
buffer
size
buffer
, in characters. Size in chars for snprintf
or size in wchar_ts for the wide-character functions.
format
argument
Let len
be the length of the formatted data string, not including the terminating null. len
and size
are in bytes
for _snprintf
, wchar_t
for _snwprintf
.
If len < size, len characters are stored in buffer, a null-terminator is appended, and len is returned.
In the case of snprintf
and _snwprintf
:
len
= size
, len
characters are stored in buffer, no null-terminator is appended, and len
is returned.
len
> size
, size
characters are stored in buffer, no null-terminator is appended, and a negative value is returned.
buffer
is a NULL
pointer and size
is zero, len
is returned as the count of characters required to format the output, not including the terminating null. To make a successful call with the same arguments, allocate a buffer holding at least len + 1 characters. In the case of snprintf_s and snwprintf_s
, if the storage required to store the data and a terminating null exceeds size, the functions set buffer to an empty string, errno
is set to ERANGE, and return -1. If buffer
or format
is a NULL pointer, or if size is less than or equal to zero, these functions set errno
to EINVAL and return -1.
The ordinary characters and escape sequences are copied to buffer
in order of their appearance.
Versions | Defined in | Include | Link to |
---|---|---|---|
INtime 3.0 | intime/rt/include/stdio.h | stdio.h | clib.lib |